import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDSkillEffect {
	/**序号*/
	id,
	/**效果类型*/
	effectType,
	/**基础参数1*/
	para_1,
	/**基础参数1成长值*/
	paraGrow_1,
	/**基础参数2*/
	para_2,
	/**基础参数2成长值*/
	paraGrow_2,
	/**初始效果触发几率*/
	rate,
	/**触发几率成长值*/
	rateGrow,
	/**效果持续时间(毫秒数)*/
	last,
	/**生效次数--填写0/1：0为永久生效，1为生效1次*/
	hp,
	/**最大堆叠数--填0/n，0为不可堆叠，n为最多堆叠n层。*/
	maxStack,
	/**0=buff--1=debuff*/
	isDebuff,
	/**战斗中出现的效果图标--填0不出现效果图标*/
	icon,
	/**战斗中出现的效果图标描述*/
	effectNote,
	/**受击特效*/
	hitResource,
	/**特效大小比例，单位/百分比*/
	effectSize,
	/**特效偏移[x,y],单位像素/100*/
	effectOffset,
	/**特效延迟时间/ms*/
	effectDelay,
	/**buff位置（不填默认0）--0 角色下方--1 左上角*/
	place,

	/**枚举数量*/
	EnumCount
}



export class CDSkillEffect{
	/**序号*/
	public id: number;
	/**效果类型*/
	public effectType: number;
	/**基础参数1*/
	public para_1: number;
	/**基础参数1成长值*/
	public paraGrow_1: number;
	/**基础参数2*/
	public para_2: number;
	/**基础参数2成长值*/
	public paraGrow_2: number;
	/**初始效果触发几率*/
	public rate: number;
	/**触发几率成长值*/
	public rateGrow: number;
	/**效果持续时间(毫秒数)*/
	public last: number;
	/**生效次数--填写0/1：0为永久生效，1为生效1次*/
	public hp: number;
	/**最大堆叠数--填0/n，0为不可堆叠，n为最多堆叠n层。*/
	public maxStack: number;
	/**0=buff--1=debuff*/
	public isDebuff: number;
	/**战斗中出现的效果图标--填0不出现效果图标*/
	public icon: number;
	/**战斗中出现的效果图标描述*/
	public effectNote: number;
	/**受击特效*/
	public hitResource: string;
	/**特效大小比例，单位/百分比*/
	public effectSize: number;
	/**特效偏移[x,y],单位像素/100*/
	public effectOffset: number[];
	/**特效延迟时间/ms*/
	public effectDelay: number;
	/**buff位置（不填默认0）--0 角色下方--1 左上角*/
	public place: number;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDSkillEffect.id: return this.id;
			case E_CDSkillEffect.effectType: return this.effectType;
			case E_CDSkillEffect.para_1: return this.para_1;
			case E_CDSkillEffect.paraGrow_1: return this.paraGrow_1;
			case E_CDSkillEffect.para_2: return this.para_2;
			case E_CDSkillEffect.paraGrow_2: return this.paraGrow_2;
			case E_CDSkillEffect.rate: return this.rate;
			case E_CDSkillEffect.rateGrow: return this.rateGrow;
			case E_CDSkillEffect.last: return this.last;
			case E_CDSkillEffect.hp: return this.hp;
			case E_CDSkillEffect.maxStack: return this.maxStack;
			case E_CDSkillEffect.isDebuff: return this.isDebuff;
			case E_CDSkillEffect.icon: return this.icon;
			case E_CDSkillEffect.effectNote: return this.effectNote;
			case E_CDSkillEffect.hitResource: return this.hitResource;
			case E_CDSkillEffect.effectSize: return this.effectSize;
			case E_CDSkillEffect.effectOffset: return this.effectOffset;
			case E_CDSkillEffect.effectDelay: return this.effectDelay;
			case E_CDSkillEffect.place: return this.place;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDSkillEffect.id: this.id = v; break;
			case E_CDSkillEffect.effectType: this.effectType = v; break;
			case E_CDSkillEffect.para_1: this.para_1 = v; break;
			case E_CDSkillEffect.paraGrow_1: this.paraGrow_1 = v; break;
			case E_CDSkillEffect.para_2: this.para_2 = v; break;
			case E_CDSkillEffect.paraGrow_2: this.paraGrow_2 = v; break;
			case E_CDSkillEffect.rate: this.rate = v; break;
			case E_CDSkillEffect.rateGrow: this.rateGrow = v; break;
			case E_CDSkillEffect.last: this.last = v; break;
			case E_CDSkillEffect.hp: this.hp = v; break;
			case E_CDSkillEffect.maxStack: this.maxStack = v; break;
			case E_CDSkillEffect.isDebuff: this.isDebuff = v; break;
			case E_CDSkillEffect.icon: this.icon = v; break;
			case E_CDSkillEffect.effectNote: this.effectNote = v; break;
			case E_CDSkillEffect.hitResource: this.hitResource = v; break;
			case E_CDSkillEffect.effectSize: this.effectSize = v; break;
			case E_CDSkillEffect.effectOffset: this.effectOffset = v; break;
			case E_CDSkillEffect.effectDelay: this.effectDelay = v; break;
			case E_CDSkillEffect.place: this.place = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDSkillEffect> = new HashMap<number, CDSkillEffect>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDSkillEffect[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDSkillEffect();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].effectType = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].para_1 = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].paraGrow_1 = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].para_2 = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].paraGrow_2 = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].rate = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].rateGrow = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].last = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].hp = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].maxStack = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].isDebuff = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].icon = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].effectNote = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].hitResource = byte.readString();
		}
		for (i = 0; i < size; i++) {
			list[i].effectSize = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].effectOffset = [];
			const attrArray = list[i].effectOffset;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].effectDelay = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].place = byte.readInt32();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDSkillEffect{
		return this.datas ? this.datas.get(id) : null;
	}
}
